#include <QDebug>
#include "applicationconfiguration.h"
#include "configreader.h"

// init static members of app configuration
Host ApplicationConfiguration::myHost = Host();
QList<Host> ApplicationConfiguration::remoteHosts = QList<Host>();

ApplicationConfiguration::ApplicationConfiguration()
{
}

bool ApplicationConfiguration::loadConfig(QString filepath){

    ConfigReader cr;
    return cr.readConfigFile(filepath, &myHost, &remoteHosts);
}


ApplicationConfiguration& ApplicationConfiguration::getInstance(){
    static ApplicationConfiguration instance;
    return instance;
}

void ApplicationConfiguration::printAppConfiguration(){

    qDebug() << "Local app configuration:" << "\nId:" << myHost.getId() << "\nPort:" << myHost.getPort() << "\n";

    for(int i = 0; i < remoteHosts.size(); ++i){
        qDebug() << "Remote host: " << i+1 << "\nId:" << remoteHosts[i].getId() << "\nPort:" << remoteHosts[i].getPort() << "\nHost name:" << remoteHosts[i].getHostName() << "\n";
    }

}
